﻿$file = "F:\2014\7-22-new-2014-08-26.docx"

<#        Get-DocumentText        #>
<#
$wordApp = New-Object -COM Word.Application
$file = "F:\2014\7-22-new-2014-08-23.docx"#(dir F:\2014\7-22-new-2014-08-23).FullName
$doc = $wordApp.Documents.Open($file)
$text = $doc.Content.Text
$text
$wordApp.Exit
#>
<#  Get-DocumentParagraph   
$wordApp = New-Object -COM Word.Application
#$file = (dir Sample.doc).FullName
$doc = $wordApp.Documents.Open($file)
$paragraphs = $doc.Paragraphs
foreach ($paragraph in $Paragraphs)
{
Write-Host "PARAGRAPH:"
Write-Host $paragraph.Range.Text
}
$wordApp.Quit()
 #>

 <#  Get-DocumentSentences 
 $wordApp = New-Object -COM Word.Application
#$file = (dir Sample.doc).FullName
$doc = $wordApp.Documents.Open($file)
$sentences = $doc.Sentences
foreach ($sentence in $sentences)
{
Write-Host "Sentence:"
Write-Host $sentence.Text
}
$wordApp.Quit()

   #>


  <# 只保留Doc文档的格式;内容全部删除
$word = New-Object -comobject Word.Application 
$word.Visible = $True 
 
$doc = $word.Documents.Open("F:\2014\7-22-new-2014-09-11.docx") 
 
$sel = $word.Selection 
$paras = $doc.Paragraphs  #段落
 
foreach ($para in $paras) 
{ 
    $style = $para.Style 
    If ($style.NameLocal -ne "Heading 1") 
    { 
        $para.Range.Select() 
        $sel.Cut() 
    } 
} 
$doc.SaveAs([ref] "F:\2014\Headings.doc") 
$word.Quit() 
#>
$rows = 2; $columns = 5

$word = New-Object -ComObject word.application

$word.visible = $true

$document = $word.documents.add()

$range = $document.Range()

 

$table = $document.Tables.add($range,$rows,$columns)

$table.cell(1,1).range.text = "code"

$table.cell(1,2).range.text = "wingdings"

$table.cell(1,3).range.text = "wingdings2"

$table.cell(1,4).range.text = "wingdings3"

$table.cell(1,5).range.text = "courier new"

$j=2

For($i = 33 ; $i -le 255; $i++)

{

 $table.rows.add() | out-null

 $Table.Cell($j,1).range.Text = $i

 $cellRange = $Table.Cell($j,2).range

 $cellRange.collapse()

 $cellRange.InsertSymbol($i,"WingDings")

 $cellrange = $table.cell($j,3).range

 $cellrange.collapse()

 $cellrange.insertSymbol($i,"wingdings2")

 $cellrange = $table.cell($j,4).range

 $cellrange.collapse()

 $cellrange.insertSymbol($i,"wingdings3")

 $cellrange = $table.cell($j,5).range

 $cellrange.collapse()

 $cellrange.insertSymbol($i,"Courier New")

 $j++

}